<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link href="/css/layui.css" th:href="@{/css/layui.css}" rel="stylesheet">
<body class="gray-bg">
<div class="wrapper wrapper-content ">
	<div class="row">
		<div class="col-sm-12">
			<div class="ibox float-e-margins">
				<div class="ibox-content">
					<form class="form-horizontal m-t" id="signupForm">
						<input id="id" name="id" class="form-control" type="hidden">
						<div class="form-group">
							<label class="col-sm-3 control-label">小程序名称：</label>
							<div class="col-sm-8">
								<input id="appName" name="appName" class="form-control" type="text">
							</div>
						</div>


						<div class="form-group">
							<label class="col-sm-3 control-label">分享标题：</label>
							<div class="col-sm-8">
								<input id="shareTitle" name="shareTitle" class="form-control" type="text">
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">启用随机语录：</label>
							<div class="col-sm-8">
								<select id="randomQuo" name="randomQuo" class="form-control">
									<option value="0">否</option>
									<option value="1">是</option>
								</select>
							</div>
						</div>

						<div class="form-group">
							<label class="col-sm-3 control-label">开启下载：</label>
							<div class="col-sm-8">
								<select id="isTools" name="isTools" class="form-control">
									<option value="0">否</option>
									<option value="1">是</option>
								</select>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">分享图片：</label>
							<div class="col-sm-8">
								<input id="shareImg" name="shareImg" class="form-control" type="hidden">
								<button type="button" class="layui-btn" id="shareImg_upload">
									<i class="fa fa-cloud"></i>上传文件
								</button>
								<div class="layui-upload-list">
									<img class="layui-upload-img" id="shareImg_src" style="width: 100px;height: 100px;">
								</div>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">小程序背景图：</label>
							<div class="col-sm-8">
								<input id="appBg" name="appBg" class="form-control" type="hidden">
								<button type="button" class="layui-btn" id="appBg_upload">
									<i class="fa fa-cloud"></i>上传文件
								</button>
								<div class="layui-upload-list">
									<img class="layui-upload-img" id="appBg_src" style="width: 100px;height: 100px;">
								</div>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">小程序logo：</label>
							<div class="col-sm-8">
								<input id="appLogo" name="appLogo" class="form-control" type="hidden">
								<button type="button" class="layui-btn" id="appLogo_upload">
									<i class="fa fa-cloud"></i>上传文件
								</button>
								<div class="layui-upload-list">
									<img class="layui-upload-img" id="appLogo_src" style="width: 100px;height: 100px;">
								</div>
							</div>
						</div>


						<div class="form-group">
							<div class="col-sm-8 col-sm-offset-3">
								<button type="submit" class="btn btn-primary" id="saveBtn" onclick="update()">提交</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
<div th:include="include::footer"></div>
<script src="/js/layui.js" th:src="@{/js/layui.js}"></script>

<script type="text/javascript">

	//onclick="update()"

	layui.use('upload', function () {
		var upload = layui.upload;
		var upload = layui.upload;
		//执行实例
		upload.render({
			elem: '#shareImg_upload', //绑定元素
			url: ctxPath+'common/sysFile/upload/oss', //上传接口
			size: 51200,
			accept: 'file',
			exts: 'jpg|png|jpeg|bpm',
			before: function(obj){
				//预读本地文件示例，不支持ie8
				obj.preview(function(index, file, result){
					$('#shareImg_src').attr('src', result); //图片链接（base64）
				});
				//layer.msg('上传中', {icon: 16, time: 0});
			},
			done: function (res,index, upload) {
				layer.msg(res.msg);
				$('#shareImg').val(res.fileName);
			},
			error: function (r) {
				layer.msg(r.msg);
			}
		});

		upload.render({
			elem: '#appBg_upload', //绑定元素
			url: ctxPath+'common/sysFile/upload/oss', //上传接口
			size: 51200,
			accept: 'file',
			exts: 'jpg|png|jpeg|bpm',
			before: function(obj){
				//预读本地文件示例，不支持ie8
				obj.preview(function(index, file, result){
					$('#appBg_src').attr('src', result); //图片链接（base64）
				});
				//layer.msg('上传中', {icon: 16, time: 0});
			},
			done: function (res,index, upload) {
				layer.msg(res.msg);
				$('#appBg').val(res.fileName);
			},
			error: function (r) {
				layer.msg(r.msg);
			}
		});

		upload.render({
			elem: '#appLogo_upload', //绑定元素
			url: ctxPath+'common/sysFile/upload/oss', //上传接口
			size: 51200,
			accept: 'file',
			exts: 'jpg|png|jpeg|bpm',
			before: function(obj){
				//预读本地文件示例，不支持ie8
				obj.preview(function(index, file, result){
					$('#appLogo_src').attr('src', result); //图片链接（base64）
				});
				//layer.msg('上传中', {icon: 16, time: 0});
			},
			done: function (res,index, upload) {
				layer.msg(res.msg);
				$('#appLogo').val(res.fileName);
			},
			error: function (r) {
				layer.msg(r.msg);
			}
		});
	})

	getData();
	function getData() {
		$.ajax({
			cache : true,
			type : "get",
			url : ctxPath+ "/wallpaper/bzBaseinfo/get",
			async : false,
			error : function(request) {
			},
			success : function(data) {
				let baseinfoDO = data.baseinfoDO;
				if (data.code == 0 && baseinfoDO != null) {
					$("#id").val(baseinfoDO.id);
					$("#appName").val(baseinfoDO.appName);
					$("#shareImg").val(baseinfoDO.shareImg);
					$("#shareTitle").val(baseinfoDO.shareTitle);
					$("#randomQuo").val(baseinfoDO.randomQuo);
					$("#appBg").val(baseinfoDO.appBg);
					$("#isTools").val(baseinfoDO.isTools);
					$("#appLogo").val(baseinfoDO.appLogo);

					if(baseinfoDO.shareImg){
						$("#shareImg_src").attr("src",baseinfoDO.shareImg);
					}
					if(baseinfoDO.appBg){
						$("#appBg_src").attr("src",baseinfoDO.appBg);
					}
					if(baseinfoDO.appLogo){
						$("#appLogo_src").attr("src",baseinfoDO.appLogo);
					}

				}

			}
		});
	}


	function update() {
		$.ajax({
			cache : true,
			type : "POST",
			url : ctxPath+ "/wallpaper/bzBaseinfo/update",
			data : $('#signupForm').serialize(),// 你的formid
			async : false,
			error : function(request) {
				parent.layer.alert("Connection error");
			},
			success : function(data) {
				if (data.code == 0) {
					parent.layer.msg("操作成功");
				} else {
					parent.layer.alert(data.msg)
				}

			}
		});

	}
</script>
</body>
</html>
